/*
 * Copyright (c) 2006 - 2022, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

/**
 * <p>Project: app2022 - Demo
 * <p>Powered by webrx On 2022-01-27 09:24:37
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class Demo {
    public static void one(String[] args) {
        //单线程串行
        for (int i = 0; i < 5; i++) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.printf("A=%d%n", i);
        }

        for (int i = 0; i < 5; i++) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.printf("B=%d%n", i);
        }
    }

    public static void main(String[] args) {

        //两个线程，并行执行(CPU分时作业调度)
        new Thread(() -> {
            for (int i = 0; i < 5; i++) {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.printf("A=%d%n", i);
            }
        }).start();

        new Thread(() -> {
            for (int j = 0; j < 5; j++) {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.printf("B=%d%n", j);
            }
        }).start();

        try {
            Thread.sleep(3000);
            System.out.println("helloworld");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

    }
}
